{extend name="layout"}
{block name="body"}   
    <section class="wld-content">
        <div class="page_title">增员信息表</div>
        
        <div class="con_box layui-form">
            
            {if $increase.status eq 3}<div class="topTips">反馈信息：{$increase.feedback|default=""}</div>{/if}
            <form class="layui-form-type layui-form mainForm" data-auto="true" data-callback="submitCallback">
                <div class="con_title">
                    <span class="con_title_line"></span>
                    <span>员工信息</span>
                </div>
                <div class="add-input layui-form-item">
                    <div class="layui-row ">
                        <div class="layui-col-md4">
                            <div class="layui-inline ">
                                <label class="layui-form-label label-required-prev">姓名</label>
                                <div class="layui-input-inline seller-inline-input">
                                    <input type="text" name="name" required placeholder="请输入姓名" autocomplete="off" value="{$increase.name|default=""}" class="layui-input ">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-inline ">
                                <label class="layui-form-label label-required-prev">身份证号</label>
                                <div class="layui-input-inline seller-inline-input">
                                    <input type="text" name="id_number" required placeholder="请输入身份证号" autocomplete="off"
                                           value="{$increase.id_number|default=""}"
                                    class="layui-input ">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-inline ">
                                <label class="layui-form-label label-required-prev">电话号码</label>
                                <div class="layui-input-inline seller-inline-input">
                                    <input type="text" name="mobile" required placeholder="请输入电话号码" autocomplete="off"
                                           value="{$increase.mobile|default=""}"
                                    class="layui-input ">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-inline layui-form-item ">
                                <label class="layui-form-label label-required-prev">服务账期</label>
                                <div class="layui-input-inline  seller-inline-input">
                                    <input type="text" name="start_date" value="{$increase.start_date|default=""}" required readonly
                                    placeholder="请选择服务账期"
                                    class="layui-input" autocomplete="off">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-inline ">
                                <label class="layui-form-label label-required-prev">月发工资</label>
                                <div class="layui-input-inline seller-inline-input">
                                    <input type="number" name="wage" required placeholder="请输入月发工资" autocomplete="off"
                                           value="{$increase.wage|default=""}"
                                    class="layui-input ">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-inline ">
                                <label class="layui-form-label label-required-prev">托管档案</label>
                                <div class="layui-input-inline seller-inline-input">
                                    <select class="layui-select" name="archives" required>
                                        <option value="">请选择托管档案</option>
                                        <option value="1" {if $increase.archives eq 1}selected{/if}>是</option>
                                        <option value="0" {if $increase.archives eq 0}selected{/if}>否</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <!--<div class="layui-col-md4">
                            <div class="layui-inline ">
                                <label class="layui-form-label">银行卡号</label>
                                <div class="layui-input-inline seller-inline-input">
                                    <input type="text" name="bank_account"  placeholder="请输入银行卡号" autocomplete="off"
                                           value="{$increase.bank_account|default=""}"
                                    class="layui-input ">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-inline ">
                                <label class="layui-form-label ">开户银行</label>
                                <div class="layui-input-inline seller-inline-input">
                                    <input type="text" name="bank"  placeholder="请输入开户银行" autocomplete="off"
                                           value="{$increase.bank|default=""}"
                                    class="layui-input ">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md4">
                            <div class="layui-inline ">
                                <label class="layui-form-label ">银行号码</label>
                                <div class="layui-input-inline seller-inline-input">
                                    <input type="text" name="bank_number"  placeholder="请输入银行号码" autocomplete="off"
                                           value="{$increase.bank_number|default=""}"
                                    class="layui-input ">
                                </div>
                            </div>
                        </div>-->
                    </div>
                </div>
                <div class="con_title">
                    <span class="con_title_line"></span>
                    <span>保险信息</span>
                </div>
                <div class="add-table">
                    <table  class="layui-table table-add insurance_type" lay-skin="nob" >
                        <colgroup>
                            
                            <col width="175">
                            <col width="135">
                            <col width="196">
                            <col width="196">
                            <col width="196">
                            <col width="164">
                          </colgroup>
                          <thead>
                            <tr>
                                <th>保险类型</th>
                                <th>是否缴纳</th>
                                <th>起始日期</th>
                                <th>社保工资</th>
                                <th>公司基数</th>
                                <th>个人基数</th>
                            </tr> 
                          </thead>
                          <tbody>
                            <tr data-insurance="1" {if ($increase_insurance.0.status eq 0) or ($insurances.0.status eq 0)}class="notChange"{/if}>
                              <td>养老保险</td>
                              <td> <input type="checkbox" name="insurance_status[1]" lay-skin="switch" lay-filter="switch" lay-text="是|否" {if $increase_insurance.0.status neq 0} checked {/if}{if $insurances.0.status eq 0} disabled {/if}></td>
                              <td> 
                                <div class="input-item input-icon">
                                    <i class="iconfont iconweimingmingwenjianjia_rili"></i>  
                                    <input   name="insurance_start_date[1]" placeholder="请选择"  value="{$increase_insurance.0.start_date|default=""}" class="layui-input startDate1" autocomplete="off" {if ($increase_insurance.0.status eq 0) or ($insurances.0.status eq 0)} disabled {else/} required{/if}>
                                 </div>
                              </td>
                              <td><div class="input-item input-icon">
                                <i class="iconfont iconrenminbi"></i>  
                                <input type="hidden" name="insurance_area[1]" id=""  value="{$insurances.0.area|default=0}" />
                                <input type="text" name="insurance_wage[1]"  lay-verify="required" value="{$increase_insurance.0.wage|default=""}" placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.0.status eq 0) or ($insurances.0.status eq 0)} disabled {else/} required {/if}> </div>   </td>
                              <td><div class="input-item"><input type="text" title=" " name="company_base[1]" value="{$increase_insurance.0.company_base|default=""}" readonly   lay-verify="required" placeholder="" autocomplete="off" class="layui-input"> </div>   </td>
                              <td><div class="input-item"><input type="text" title=" " name="personal_base[1]" value="{$increase_insurance.0.personal_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">  </div>  </td>
                            </tr>
                            <tr  data-insurance="2" {if ($increase_insurance.1.status eq 0) or ($insurances.1.status eq 0)}class="notChange"{/if}>
                                <td>工伤保险</td>
                                <td> <input type="checkbox" name="insurance_status[2]" lay-skin="switch" lay-filter="switch" lay-text="是|否" {if $increase_insurance.1.status neq 0} checked {/if}{if $insurances.1.status eq 0} disabled{/if}></td>
                                <td> 
                                  <div class="input-item input-icon">
                                      <i class="iconfont iconweimingmingwenjianjia_rili"></i>  
                                      <input   placeholder="请选择" name="insurance_start_date[2]"  value="{$increase_insurance.1.start_date|default=""}" class="layui-input startDate1" autocomplete="off" {if ($increase_insurance.1.status eq 0) or ($insurances.1.status eq 0)} disabled {else/} required {/if}>
                                   </div>
                                </td>
                                <td><div class="input-item input-icon">
                                  <i class="iconfont iconrenminbi"></i> 
                                  <input type="hidden" name="insurance_area[2]" id=""  value="{$insurances.1.area|default=0}" />
                                  <input type="text" name="insurance_wage[2]"  lay-verify="required"  value="{$increase_insurance.1.wage|default=""}" placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.1.status eq 0) or ($insurances.1.status eq 0)} disabled {else/} required {/if}> </div>   </td>
                                <td><div class="input-item"><input type="text" title=" " name="company_base[2]" value="{$increase_insurance.1.company_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input"> </div>   </td>
                                <td><div class="input-item"><input type="text" title=" " name="personal_base[2]" value="{$increase_insurance.1.personal_base|default=""}" readonly  lay-verify="required" placeholder=" " autocomplete="off" class="layui-input">  </div>  </td>
                              </tr>
                              <tr  data-insurance="3" {if ($increase_insurance.2.status eq 0) or ($insurances.2.status eq 0)}class="notChange"{/if}>
                                <td>失业保险</td>
                                <td> <input type="checkbox" name="insurance_status[3]" lay-skin="switch" lay-filter="switch" lay-text="是|否" {if $increase_insurance.2.status neq 0} checked {/if}{if $insurances.2.status eq 0} disabled{/if}></td>
                                <td> 
                                  <div class="input-item input-icon">
                                      <i class="iconfont iconweimingmingwenjianjia_rili"></i>  
                                      <input  placeholder="请选择" name="insurance_start_date[3]" value="{$increase_insurance.2.start_date|default=""}" class="layui-input startDate1" autocomplete="off" {if ($increase_insurance.2.status eq 0) or ($insurances.2.status eq 0)} disabled {else/} required {/if}>
                                   </div>
                                </td>
                                <td><div class="input-item input-icon">
                                  <i class="iconfont iconrenminbi"></i> 
                                  <input type="hidden" name="insurance_area[3]" id=""  value="{$insurances.2.area|default=0}" />
                                  <input type="text" name="insurance_wage[3]"  lay-verify="required" value="{$increase_insurance.2.wage|default=""}" placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.2.status eq 0) or ($insurances.2.status eq 0)} disabled {else/} required {/if}> </div>   </td>
                                <td><div class="input-item"><input type="text" title=" " name="company_base[3]" value="{$increase_insurance.2.company_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input"> </div>   </td>
                                <td><div class="input-item"><input type="text" title=" " name="personal_base[3]" value="{$increase_insurance.2.personal_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">  </div>  </td>
                              </tr>
                              
                              <tr data-insurance="4" {if ($increase_insurance.3.status eq 0) or ($insurances.3.status eq 0)}class="notChange"{/if}>
                                <td>医疗保险</td>
                                <td> <input type="checkbox" name="insurance_status[4]" lay-skin="switch" lay-filter="switch" lay-text="是|否" {if $increase_insurance.3.status neq 0} checked {/if}{if $insurances.3.status eq 0} disabled {/if}></td>
                                <td> 
                                  <div class="input-item input-icon">
                                      <i class="iconfont iconweimingmingwenjianjia_rili"></i>  
                                      <input  placeholder="请选择" name="insurance_start_date[4]" value="{$increase_insurance.3.start_date|default=""}" class="layui-input startDate1" autocomplete="off" {if ($increase_insurance.3.status eq 0) or ($insurances.3.status eq 0)} disabled {else/} required  {/if}>
                                   </div>
                                </td>
                                <td><div class="input-item input-icon">
                                  <i class="iconfont iconrenminbi"></i> 
                                  <input type="hidden" name="insurance_area[4]" id=""  value="{$insurances.3.area|default=0}" />
                                  <input type="text" name="insurance_wage[4]"  lay-verify="required" value="{$increase_insurance.3.wage|default=""}" placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.3.status eq 0) or ($insurances.3.status eq 0)} disabled {else/} required {/if}> </div>   </td>
                                <td><div class="input-item"><input type="text" title=" " name="company_base[4]" value="{$increase_insurance.3.company_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input"> </div>   </td>
                                <td><div class="input-item"><input type="text" title=" " name="personal_base[4]" value="{$increase_insurance.3.personal_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">  </div>  </td>
                              </tr>
                              <tr  data-insurance="5" {if ($increase_insurance.4.status eq 0) or ($insurances.4.status eq 0)}class="notChange"{/if}>
                                <td>住房公积金</td>
                                <td> <input type="checkbox" name="insurance_status[5]" lay-skin="switch" lay-filter="switch" lay-text="是|否" {if $increase_insurance.4.status neq 0} checked {/if}{if $insurances.4.status eq 0} disabled {/if}></td>
                                <td> 
                                  <div class="input-item input-icon">
                                      <i class="iconfont iconweimingmingwenjianjia_rili"></i>  
                                      <input  placeholder="请选择" name="insurance_start_date[5]" value="{$increase_insurance.4.start_date|default=""}" class="layui-input startDate1" autocomplete="off" {if ($increase_insurance.4.status eq 0) or ($insurances.4.status eq 0)} disabled {else/} required {/if}>
                                   </div>
                                </td>
                                <td><div class="input-item input-icon">
                                  <i class="iconfont iconrenminbi"></i>
                                  <input type="hidden" name="insurance_area[5]" id=""  value="{$insurances.4.area|default=0}" />
                                  <input type="text" name="insurance_wage[5]"  lay-verify="required" value="{$increase_insurance.4.wage|default=""}" placeholder="请输入" autocomplete="off" class="layui-input" {if ($increase_insurance.4.status eq 0) or ($insurances.4.status eq 0)} disabled {else/} required {/if}> </div>   </td>
                                <td><div class="input-item"><input type="text" title=" " name="company_base[5]" value="{$increase_insurance.4.company_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input"> </div>   </td>
                                <td><div class="input-item"><input type="text" title=" " name="personal_base[5]" value="{$increase_insurance.4.personal_base|default=""}" readonly  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">  </div>  </td>
                              </tr>
                          </tbody>
                    </table>                
                </div>
                <div class="add-obj">
                	<input type="hidden" name="id" id="id" value="{$increase.id|default=0}" />
                    <a class="add-back" onclick="window.history.back()">返回</a>
                    <a class="add-updata" onclick="formSubmit()">提交</a>
                </div>
            </form>
			

		</div>
    </section>
    
    {/block}
    {block name="script"}
<script>
      form.render();
	  var startDateVal = getStartDate()
	  $('.startDate1').each(function(){
		  laydate.render({
			  elem: this,       //使用this指向当前元素,不能使用class名, 否则只有第一个有效
			  format: 'yyyy-MM-dd',
			  type:'date',
			  max:startDateVal[2],
			  trigger: 'click',
			  btns: ['clear','confirm'],
			  done: function (value) {
				  // $(this.elem).val(value).trigger('change');
			  }
		  });
	  })
	  let default_zhangqi =  $('input[name="start_date"]').val()
	  if(default_zhangqi){
		  console.log(default_zhangqi)
		  let flag_val = true
	  }else{
		  $('input[name="start_date"]').val(getStartDate()[0])
	  }




	  function getStartDate  (){
		  // 15号以前 包含15 选次月
		  //16还以后 包含16 选次次月

		  var D = new Date();
		  var  y, m, d;
		  y = D.getFullYear();
		  m = D.getMonth() + 1;
		  d = D.getDate();
		  var flag = false

		  if(d<16){
			  m+=1
		  }else{
			  m+=2;
			  flag = true
		  }

		  if(m>12){
			  y+=1
			  m-=12
		  }

		  m = m > 9 ? m : '0' + m;

		  var zhangqi = y + '-' + m


		  let monthLastDay = new Date(y,m,0).getDate();
		  var default_date =  y + '-' + m + '-' + '01';
		  var end_date =  y + '-' + m + '-' + monthLastDay;

		  var default_zhangqi =  $('input[name="start_date"]').val()
		  if(default_zhangqi){
			  var n1 = default_zhangqi.split("-");
			  zhangqi =  n1[0] + '-' + n1[1]
			  monthLastDay = new Date(n1[0],n1[1],0).getDate();
			  default_date =  n1[0] + '-' + n1[1] + '-' + '01';
			  end_date =  n1[0] + '-' + n1[1] + '-' + monthLastDay;
		  }



		  return [zhangqi,default_date,end_date,flag];

	  }
	  formSubmit = function (){
		  var [e,f,g,h] = getStartDate()
		  if(h){
			  $.msg.confirm("账期是"+ e +",是否要提交？","提示" ,"tips", function (index) {
				  $('form').submit()
				  layer.close(index)
			  });

		  }else{

			  $('form').submit()
		  }

	  }

      form.on('switch(switch)', function(data){

        var tr=$(data.elem).parents("tr")
        if(data.elem.checked){
            tr.removeClass("notChange");
            tr.find("[type!='checkbox']").removeAttr("disabled").attr("required","required")
            
        }else{
            tr.addClass("notChange");
            // tr.find("[type!='checkbox']").val("").attr("disabled","disabled").removeAttr("required");
			tr.find("[name^='insurance_start_date']").val("").attr("disabled","disabled").removeAttr("required");
			tr.find("[name^='insurance_wage']").val("").attr("disabled","disabled").removeAttr("required");
			tr.find("[name^='company_base']").val("").attr("disabled","disabled").removeAttr("required");
			tr.find("[name^='personal_base']").val("").attr("disabled","disabled").removeAttr("required");

		}
        form.render();
       
        
    });
    form.on('select(company_id)', function(data){
        var $tr=$(".insurance_type tbody tr")
        if(data.value){
            $.form.load('{:url("insurances")}', {id: data.value}, "post", function (ret) {
                if (ret.code === 1) {
                    var data = ret.data;
                    for(var i=0;i<data.length;i++){
                        if(data[i].status==1){
                            $($tr[data[i].insurance-1]).removeClass("notChange");
                            $($tr[data[i].insurance-1]).find("[type='checkbox']").prop("checked",'checked').removeAttr("disabled")
                            $($tr[data[i].insurance-1]).find("[type!='checkbox']").removeAttr("disabled")
                            $('[name="insurance_area['+ data[i].insurance +']"]').val(data[i].area)
                            $('[name="insurance_status['+ data[i].insurance +']"]').val(data[i].status)
                        }else{
                            $($tr[data[i].insurance-1]).addClass("notChange");
                            $($tr[data[i].insurance-1]).find("[type='checkbox']").prop("checked",false).attr("disabled","disabled");
                            $($tr[data[i].insurance-1]).find("[type!='checkbox']").val("").attr("disabled","disabled");
                        }
                        ;
                    }
                    form.render("checkbox");
          
                } else {
                    $.msg.error(ret.info, 1)
                }
               

                 return false;
            })
        }else{
            $(".notChange").removeClass("notChange")
            $(".insurance_type tbody").find("[type='checkbox']").prop("checked",false);
            $(".insurance_type tbody").find("[type!='checkbox']").val("").removeAttr("disabled");
            form.render("checkbox");
        }

   });
    // $("[name='start_date']").change(function(){
    //     var val =$(this).val();
    //     $(".insurance_type tbody tr[class!='notChange']").each(function(){
    //         $(this).find("[name^='insurance_start_date']").val(val)
    //         // $(this).find("[name='insurance_start_date[4]']").val(getNextMonth(val))
    //     })
    //     form.render();
    // })
    $('[name="wage"]').on('change', function(){
        $(".insurance_type tbody tr[class!='notChange']").find("[name^='insurance_wage']").val($(this).val())
        $.form.load('{:url("insuranceAllBase")}', {wage: $(this).val()}, "post", function (ret) {
            if (ret.code === 1) {
                var data = ret.data;
                for(i in data){
                    
                    $(".insurance_type tbody tr[class!='notChange']").find("[name='company_base["+ i +"]']").val(data[i].company)
                    $(".insurance_type tbody tr[class!='notChange']").find("[name='personal_base["+ i +"]']").val(data[i].personal)
                }

                // for(var i=0;i<data.length;i++){
                   
                // }

            } else {
                $.msg.error(ret.info, 1)
            }
            return false;
        })
        form.render();
    })
    $("[name^='insurance_wage']").change(function(){
        var $tr=$(this).parents("tr");
        var insurance= $(this).parents("tr").attr("data-insurance");
        if($(this).val()){
            $.form.load('{:url("insuranceBase")}', {wage: $(this).val(),insurance:insurance}, "post", function (ret) {
            if (ret.code === 1) {
                var data = ret.data;
                $("[name='company_base["+ insurance +"]']").val(data.company);
                $("[name='personal_base["+ insurance +"]']").val(data.personal)
        
            } else {
                $.msg.error(ret.info, 1)
            }
            return false;
        })
        }else{
            $("[name='company_base["+ insurance +"]']").val("");
            $("[name='personal_base["+ insurance +"]']").val("")
        }
    })

 

           
           
</script>
{/block}
    {block name="style"}
    <style>
        .layui-table tbody tr:hover{
            background-color: #fff;
        }
        .layui-input-inline  input[name='start_date']{
            border: 1px solid #e5e5e5;
            background: #fff;
            color: #9c9cae;
            cursor: auto;
        }
        .layui-input-inline  input[name='start_date']:focus {
            border: 1px solid #61cad7 !important;
        }
    </style>
    {/block}


